package jjsan.callback;

import jjsan.callback.phone.Hc;
import jjsan.callback.phone.R;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Spinner;
import android.widget.Toast;

public class BaseActivity extends Activity {
	protected SharedPreferences p;
	protected Boolean debugOn;
	public int PAUSETIME = 0;
	
	


	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		  // refresh your views here
		  super.onConfigurationChanged(newConfig);
	Toast.makeText(getApplicationContext(), "Changing language",
					Toast.LENGTH_SHORT).show();
	}	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		p = getSharedPreferences(Hc.PREFSNAME, 0);
		debugOn = true;
	}
	
	protected void debugLog(String extra,String s) {
		if (debugOn) Log.d(Hc.LOG_TAG, Hc.PRE_TAG + extra + Hc.POST_TAG + " "+ s);
	}
	protected void errorLog(String extra,String s) {
		Log.e(Hc.LOG_TAG, Hc.PRE_TAG + extra + Hc.POST_TAG + " "+ s);
	}
	
	public class TimeSpinnerChange implements OnItemSelectedListener {
		public static final String PREFS_NAME = "MyPrefsFile";
	    public void onItemSelected(AdapterView<?> parent,
	        View view, int pos, long id) {
	    	//save pause time to preferences
	    	SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
	        SharedPreferences.Editor editor = settings.edit();
	      
	        Spinner spinner = (Spinner) findViewById(R.id.spinner);
	        
	        editor.putInt("pause_time", spinner.getSelectedItemPosition());
	    
	        // Commit the edits!
	        editor.commit();
	        
	    	//int tmp = settings.getInt("pause_time", 0);
	    	//show some toast about it
	    	//Toast.makeText(parent.getContext(), getString(R.string.pause_time_toast) +" "+tmp+"s..." , Toast.LENGTH_LONG).show();	          
	    }

	    public void onNothingSelected(AdapterView<?> parent) {
	      // Do nothing.
	    }
	}
		public class LanguageSpinnerChange implements OnItemSelectedListener {
			public static final String PREFS_NAME = "MyPrefsFile";
		    public void onItemSelected(AdapterView<?> parent,
		        View view, int pos, long id) {
		    	//save pause time to preferences
		    	SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
		        SharedPreferences.Editor editor = settings.edit();
		      
		        Spinner spinner = (Spinner) findViewById(R.id.spinner2);

		        int tmp = settings.getInt("language", 0);
		        
			    if (spinner.getSelectedItemPosition()!=tmp)
		    	{
		        editor.putInt("language", spinner.getSelectedItemPosition());
		    
		        // Commit the edits!
		        editor.commit();
		    	System.exit(0);
		    	}
		    	tmp = settings.getInt("language", 0);
		    	//show some toast about it
		    	//Toast.makeText(parent.getContext(), getString(R.string.language_toast), Toast.LENGTH_LONG).show();	     

		    }

		    public void onNothingSelected(AdapterView<?> parent) {
		      // Do nothing.
		    }
		}
		
}
